package tools

import (
	"com.lh.basic.service/config"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"google.golang.org/grpc/keepalive"
	"time"
)

func Proxy(key string) (*grpc.ClientConn, error) {
	serve := config.GetServe(key)
	return grpc.Dial(serve.Origin,
		grpc.WithInsecure(),
		grpc.WithTransportCredentials(insecure.NewCredentials()), // 非加密模式
		//grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")), // 加密配置
		grpc.WithTimeout(time.Second*5),
		grpc.WithKeepaliveParams(keepalive.ClientParameters{
			Time:                10 * time.Second,
			Timeout:             1 * time.Second,
			PermitWithoutStream: true,
		}),
	)
}
